import request from '../util/request'

// 获得频道
export const getArticles = (channelId, timestamp) => {
  return request({
    method: 'GET',
    url: '/v1_1/articles',
    needToken: true,
    params: {
      channel_id: channelId,
      timestamp: timestamp,
      with_top: 1
    }
  })
}

// 获取指定id文章详情
export const getArticleDetail = id => {
  return request({
    method: 'GET',
    url: `v1_0/articles/${id}`,
    needToken: true
  })
}
// 用户频道列表
export const getChannels = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/channels',
    needToken: true
  })
}

// 获取指定id文章的评论
export const getArticleComment = (type, source, offset, limit) => {
  return request({
    method: 'GET',
    url: 'v1_0/comments',
    params: {
      type,
      source,
      offset,
      limit
    }
  })
}
// 评论文章
export const sendCommentApi = (target, content, artId) => {
  return request({
    method: 'POST',
    url: 'v1_0/comments',
    needToken: true,
    data: {
      target,
      content,
      art_id: artId
    }
  })
}
// 对文章不喜欢
export const dislikeApi = target => {
  return request({
    method: 'POST',
    url: 'v1_0/article/dislikes',
    needToken: true,
    data: {
      target
    }
  })
}
// 取消对文章不喜欢
export const cancelDislikeApi = target => {
  return request({
    method: 'DELETE',
    url: `v1_0/article/dislikes/${target}`,
    needToken: true
  })
}
// 对文章喜欢
export const likeApi = target => {
  return request({
    method: 'POST',
    url: 'v1_0/article/likings',
    needToken: true,
    data: {
      target
    }
  })
}
// 取消对文章喜欢
export const cancelLikeApi = target => {
  return request({
    method: 'DELETE',
    url: `v1_0/article/likings/${target}`,
    needToken: true
  })
}
// 获取全部频道
export const getAllChannels = () => {
  return request({
    url: '/v1_0/channels',
    method: 'GET',
    needToken: true
  })
}

// 修改用户频道，使用PUT；
export const appendChannels = channels => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    },
    needToken: true
  })
}
// 删除频道
export const delChannel = channelId => {
  return request({
    url: '/v1_0/user/channels/' + channelId,
    method: 'DELETE',
    needToken: true
  })
}
// 用户不感兴趣的文章
export const dislike = articleID => {
  return request({
    method: 'POST',
    url: 'v1_0/article/dislikes',
    data: {
      target: articleID
    },
    needToken: true
  })
}
// 举报文章
export const report = (articleID, typeID) => {
  return request({
    method: 'POST',
    url: 'v1_0/article/reports',
    data: {
      target: articleID,
      type: typeID
    },
    needToken: true
  })
}
// 点赞评论
export const likeCom = target => {
  return request({
    method: 'POST',
    url: 'v1_0/comment/likings',
    data: {
      target
    },
    needToken: true
  })
}
// 取消点赞评论
export const cancelLikeCom = target => {
  return request({
    method: 'DELETE',
    url: `v1_0/comment/likings/${target}`,
    needToken: true
  })
}
// 收藏文章
export const collectArt = target => {
  return request({
    method: 'POST',
    url: 'v1_0/article/collections',
    data: {
      target
    },
    needToken: true
  })
}
// 取消收藏文章
export const cancelcollectArt = target => {
  return request({
    method: 'DELETE',
    url: `v1_0/article/collections/${target}`,
    needToken: true
  })
}
